package com.nep.NEPG.repository;

import com.nep.NEPG.dao.UserDao;
import com.nep.NEPG.model.SystemUser;
import java.util.List;

public class UserRepository {
     private final UserDao dao;

     public UserRepository() {
          this.dao = new UserDao();
     }

     public SystemUser findByUsername(String username) {
          return dao.findByUsername(username);
     }

     public SystemUser findById(String id) {
          return dao.findAll().stream()
                  .filter(user -> user.getId().equals(id))
                  .findFirst()
                  .orElse(null);
     }

     public List<SystemUser> findAll() {
          return dao.findAll();
     }

     public void save(SystemUser user) {
          dao.save(user);
     }

     public SystemUser authenticate(String username, String password) {
          SystemUser user = findByUsername(username);
          return (user != null && user.getPassword().equals(password)) ? user : null;
     }
}